import { formatSize } from '@web-utils/core'
import { buildDialog } from '@/util/dialog'

export function formatFileSize(row, column, filed) {
  return formatSize(filed)
}

export function getSpanIndexMap(rows, prop) {
  const map = {}
  for (let i = 0; i < rows.length; i++) {
    const groupVal = rows[i][prop]
    if (!map[groupVal]) {
      map[groupVal] = { start: i, span: 1 }
    } else {
      map[groupVal].span++
    }
  }
  return map
}

/**
 * 显示数据表格选择对话框
 * @param props {DataPickerProps}
 * @param listeners {DataPickerListeners}
 * @param data {object?}
 * @returns {Promise<void>}
 */
export async function showDataTablePicker(props, listeners, data) {
  await buildDialog(() => import('@/components/DataTablePicker'), {
    props,
    data,
    listeners
  })
}
